API functions
Windows API (Application Programming Interface) are functions and procedures that
exist in Windows libraries such as Kernel, User, etc..
API functions can be accessed directly from Delphi, but befor you call any function
make sure to include it's proper unit such as: Windows, ShellApi, etc..
Most of Windows API functions uses PChar instead of string, because it written in
C language which support Nul-Terminated strings (PChar).
In passing by value parameters you need only to typecast Delphi's String to PChar
such as:
var
MyApp: string;
begin
MyApp:= 'Notepad.exe';
ShellExecute(Handle, 'open', PChar(MyApp),
nil, nil, ws_Normal);
When you need to pass parameters by reference (Var parameters) you need to use PChar
such as:
var
Name: string;
PName: PChar;
Size: Cardinal;
begin
Size:= 50;
PName:= StrAlloc(50); // Allocate space for PChar
GetUserName(PName, Size);
StrDispose(PName); // Release PName
Name:= PName;
ShowMessage(Name);
See also:
User name and computer name
Windows directory
Windows temporary directory
Opening external document